Protocol stack that offloads a TCP connection from a host computer to a network interface device

ABSTRACT

A host CPU runs a network protocol processing stack that provides instructions not only to process network messages but also to allocate processing of certain network messages to a specialized network communication device, offloading some of the most time consuming protocol processing from the host CPU to the network communication device. By allocating common and time consuming network processes to the device, while retaining the ability to handle less time intensive and more varied processing on the host stack, the network communication device can be relatively simple and cost effective. The host CPU, operating according to instructions from the stack, and the network communication device together determine whether and to what extent a given message is processed by the host CPU or by the network communication device.

CROSS REFERENCE TO RELATED APPLICATIONS

The present application claims the benefit under 35 U.S.C. §120 of (andis a continuation of) U.S. patent application Ser. No. 10/706,398, filedNov. 12, 2003, now U.S. Pat. No. 6,941,386, which in turn claims thebenefit under 35 U.S.C. §120 of (and is a continuation of) U.S. patentapplication Ser. No. 10/208,093 filed Jul. 29, 2002, now U.S. Pat. No.6,697,868, which in turn claims the benefit under 35 U.S.C. §120 of (andis a continuation-in-part of) U.S. patent application Ser. No.09/514,425, filed Feb. 28, 2000, now U.S. Pat. No. 6,427,171, which inturn claims the benefit under 35 U.S.C. §120 of (and is acontinuation-in-part of): a) U.S. patent application Ser. No.09/141,713, filed Aug. 28, 1998, now U.S. Pat. No. 6,389,479, which inturn claims the benefit under 35 U.S.C. §119 of provisional application60/098,296, filed Aug. 27, 1998; b) U.S. patent application Ser. No.09/067,544, filed Apr. 27, 1998, now U.S. Pat. No. 6,226,680, which inturn claims the benefit under 35 U.S.C. §119 of provisional application60/061,809, filed Oct. 14, 1997; and c) U.S. patent application Ser. No.09/384,792, filed Aug. 27, 1999 now U.S. Pat. No. 6,434,620, which inturn claims the benefit under 35 U.S.C. §119 of provisional application60/098,296, filed Aug. 27, 1998.

U.S. Pat. No. 6,697,868 also claims the benefit under 35 U.S.C. §120 of(and is a continuation-in-part of) U.S. patent application Ser. No.09/464,283, filed Dec. 15, 1999, now U.S. Pat. No. 6,427,173, which inturn claims the benefit under 35 U.S.C. §120 of (and is acontinuation-in-part of) U.S. patent application Ser. No. 09/439,603,filed Nov. 12, 1999, now U.S. Pat. No. 6,247,060, which in turn claimsthe benefit under 35 U.S.C. §120 of (and is a continuation-in-part of)U.S. patent application Ser. No. 09/067,544, filed Apr. 27, 1998, nowU.S. Pat. No. 6,226,680, which in turn claims the benefit under 35U.S.C. §119 of provisional application 60/061,809, filed Oct. 14, 1997.

The subject matter of all of the applications listed above and patentslisted above is incorporated herein by reference.

REFERENCE TO COMPACT DISC APPENDIX

The Compact Disc Appendix (CD Appendix), which is a part of the presentdisclosure, includes three folders, designated CD Appendix A, CDAppendix B, and CD Appendix C on the compact disc. CD Appendix Acontains a hardware description language (verilog code) description ofan embodiment of a receive sequencer. CD Appendix B contains microcodeexecuted by a processor that operates in conjunction with the receivesequencer of CD Appendix A. CD Appendix C contains a device driverexecutable on the host as well as ATCP code executable on the host. Aportion of the disclosure of this patent document contains material(other than any portion of the “free BSD” stack included in CD AppendixC) which is subject to copyright protection. The copyright owner of thatmaterial has no objection to the facsimile reproduction by anyone of thepatent document or the patent disclosure, as it appears in the Patentand Trademark Office patent files or records, but otherwise reserves allcopyright rights.

TECHNICAL FIELD

The present invention relates to the management of informationcommunicated via a network, including protocol processing.

BACKGROUND

Various individuals, companies and governments have worked for manyyears to provide communication over computer networks. As differentcomputer and network architectures have been created, many types ofprotocols have evolved to facilitate that communication. Conventionally,network messages contain information regarding a number of protocollayers that allow information within the messages to be directed to thecorrect destination and decoded according to appropriate instructions,despite substantial differences that may exist between the computers orother devices transmitting and receiving the messages. Processing ofthese messages is usually performed by a central processing unit (CPU)running software instructions designed to recognize and manipulateprotocol information contained in the messages.

With the increasing prevalence of network communication, a large portionof the CPU's time may be devoted to such protocol processing,interfering with other tasks the CPU may need to perform. Multipleinterrupts to the CPU can also be problematic when transferring manysmall messages or for large data transfers, which are conventionallydivided into a number of packets for transmission over a network.

SUMMARY

In accordance with the present invention, means for offloading some ofthe most time consuming protocol processing from a host CPU to aspecialized device designed for network communication processing areprovided. The host has a protocol processing stack that providesinstructions not only to process network messages but also to allocateprocessing of certain network messages to the specialized networkcommunication device. By allocating some of the most common and timeconsuming network processes to the network communication device, whileretaining the ability to handle less time intensive and more variedprocessing on the host stack, the network communication device can berelatively simple and cost effective. The host CPU, operating accordingto the instructions from the stack, and the specialized networkcommunication device together determine whether and to what extent agiven message is processed by the host CPU or by the networkcommunication device.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a schematic plan view of a host computer having an intelligentnetwork interface card or communication processing device (INIC/CPD)connected to a remote host via a network.

FIG. 2 is a schematic plan view of a protocol processing stack of thepresent invention passing a connection context between host storage andthe INIC/CPD.

FIG. 3 is a diagram of a general method employed to process messagesreceived by the host computer via the INIC/CPD.

FIG. 4 illustrates a handout of the connection context from the hostprotocol processing stack to the INIC/CPD via a miniport driverinstalled in the host.

FIG. 5 shows a return of the connection context to the host protocolprocessing stack from the INIC/CPD via a miniport driver installed inthe host.

FIG. 6 diagrams a control mechanism for transmitting a message via thefast-path.

FIG. 7 diagrams a control mechanism for receiving a message via thefast-path.

DESCRIPTION OF THE PREFERRED EMBODIMENT

Referring now to FIG. 1, the present invention can operate in anenvironment including a host computer shown generally at 20 connected toa remote host 22 via a network 25. The host 20 includes a centralprocessing unit (CPU) 28 and storage 35, while an intelligent networkinterface card or communication processing device (INIC/CPD) 30 providesan interface between the host and the network 25. A computer is definedin the present invention to be a device including a CPU, a memory andinstructions for running the CPU. The network 25 is a medium fortransmission of information from one computer to another, such asconductive wires, optical fibers or wireless space, including anysupporting hardware or software such as switches and routers. Networkimplementations include local area networks, wide area networks,telecommunication networks and the Internet. The INIC/CPD 30 is depictedon a border of host 20 because the INIC/CPD provides a network interfacethat may be added with an adapter card, for example, or integrated as apart of the host computer. A bus 33 such as a peripheral componentinterface (PCI) bus provides a connection within the host 20 between theCPU 28, the INIC/CPD 30, and a storage device 35 such as a semiconductormemory or disk drive, along with any related controls.

Referring additionally to FIG. 2, the host CPU 28 runs a protocolprocessing stack 44 of instructions stored in storage 35, the stackincluding a data link layer 36, network layer 38, transport layer 40,upper layer 46 and an upper layer interface 42. A general description ofthese protocol layers can be found in the book by W. Richard Stevensentitled TCP/IP Illustrated, Volume 1 (13^(th) printing, 1999), which isincorporated herein by reference. The upper layer 46 may represent asession, presentation and/or application layer, depending upon theparticular protocol being employed and message communicated. The upperlayer interface 42, along with the CPU 28 and any related controls cansend or retrieve data to or from the upper layer 46 or storage 35, asshown by arrow 48. The upper layer interface 42 may be called aTransport driver interface (TDI), for example, in accord with Microsoftterminology. A connection context 50 has been created, as will beexplained below, the context summarizing various features of a messageconnection, such as the protocol types, source and destination addressesand status of the message. The context 50 may be passed between aninterface for the session layer 42 and the INIC/CPD 30, as shown byarrows 52 and 54, and stored as a communication control block (CCB) ofinformation in either an INIC/CPD 30 memory or storage 35.

When the INIC/CPD 30 holds a CCB defining a particular connection, datareceived by the INIC/CPD from the network and pertaining to theconnection is referenced to that CCB and can then be sent directly tostorage 35 according to a fast-path 58, bypassing sequential protocolprocessing by the data link 36, network 38 and transport 40 layers.Transmitting a message, such as sending a file from storage 35 to remotehost 22, can also occur via the fast-path 58, in which case the contextfor the file data is added by the INIC/CPD 30 referencing the CCB,rather than by sequentially adding headers during processing by thetransport 40, network 38 and data link 36 layers. The DMA controllers ofthe INIC/CPD 30 can perform these message transfers between INIC/CPD andstorage 35.

The INIC/CPD 30 can collapse multiple protocol stacks each havingpossible separate states into a single state machine for fast-pathprocessing. The INIC/CPD 30 does not handle certain exception conditionsin the single state machine, primarily because such conditions occurrelatively infrequently and to deal with them on the INIC/CPD wouldprovide little performance benefit to the host. A response to suchexceptions can be INIC/CPD 30 or CPU 28 initiated. The INIC/CPD 30 dealswith exception conditions that occur on a fast-path CCB by passing backor flushing to the host protocol stack 44 the CCB and any associatedmessage frames involved, via a control negotiation. The exceptioncondition is then processed in a conventional manner by the hostprotocol stack 44. At some later time, usually directly after thehandling of the exception condition has completed and fast-pathprocessing can resume, the host stack 44 hands the CCB back to theINIC/CPD. This fallback capability enables most performance-impactingfunctions of the host protocols to be quickly processed by thespecialized INIC/CPD hardware, while the exceptions are dealt with bythe host stacks, the exceptions being so rare as to negligibly effectoverall performance.

FIG. 3 diagrams a general flow chart for messages sent to the host viathe network according to the current invention. A large TCP/IP messagesuch as a file transfer may be received by the host from the network ina number of separate, approximately 64 KB transfers, each of which maybe split into many, approximately 1.5 KB frames or packets fortransmission over a network. Novel NetWare® protocol suites runningSequenced Packet Exchange Protocol (SPX) or NetWare® Core Protocol (NCP)over Internetwork Packet Exchange (IPX) work in a similar fashion.Another form of data communication which can be handled by the fast-pathis Transaction TCP (hereinafter T/TCP or TTCP), a version of TCP whichinitiates a connection with an initial transaction request after which areply containing data may be sent according to the connection, ratherthan initiating a connection via a several-message initializationdialogue and then transferring data with later messages. In general, anyprotocol for which a connection can be set up to define parameters for amessage or plurality of messages between network hosts may benefit fromthe present invention. In any of the transfers typified by theseprotocols, each packet conventionally includes a portion of the databeing transferred, as well as headers for each of the protocol layersand markers for positioning the packet relative to the rest of thepackets of this message.

When a message packet or frame is received 47 from a network by theINIC/CPD, it is first validated by a hardware assist. This includesdetermining the protocol types of the various layers of the packet,verifying relevant checksums, and summarizing 57 these findings into astatus word or words. Included in these words is an indication whetheror not the frame is a candidate for fast-path data flow. Selection 59 offast-path candidates is based on whether the host may benefit from thismessage connection being handled by the INIC/CPD, which includesdetermining whether the packet has header bytes denoting particularprotocols, such as TCP/IP or SPX/IPX for example. The typically smallpercentage of frames that are not fast-path candidates are sent 61 tothe host protocol stacks for slow-path protocol processing. Subsequentnetwork microprocessor work with each fast-path candidate determineswhether a fast-path connection such as a TCP or SPX CCB is alreadyextant for that candidate, or whether that candidate may be used to setup a new fast-path connection, such as for a TTCP/IP transaction. Thevalidation provided by the INIC/CPD provides advantages whether a frameis processed by the fast-path or a slow-path, as only error free,validated frames are processed by the host CPU even for the slow-pathprocessing.

All received message frames which have been determined by the INIC/CPDhardware assist to be fast-path candidates are examined 53 by thenetwork microprocessor or INIC comparator circuits to determine whetherthey match a CCB held by the INIC/CPD. Upon confirming such a match, andassuming no exception conditions exist, the INIC/CPD removes lower layerheaders and sends 69 the remaining application data from the framedirectly into its final destination in the host using direct memoryaccess (DMA) units of the INIC/CPD. This operation may occur immediatelyupon receipt of a message packet, for example when a TCP connectionalready exists and destination buffers have been negotiated, or it mayfirst be necessary to process an initial header to acquire a new set offinal destination addresses for this transfer. In this latter case, theINIC/CPD will queue subsequent message packets while waiting for thedestination address, and then DMA the queued application data to thatdestination. The final destination addresses may be provided as ascatter-gather list of host buffer address and length pairs. For aMicrosoft type operating system and stack 44, the scatter gather list isa memory descriptor data list (MDL).

A fast-path candidate that does not match a CCB may be used to set up anew fast-path connection, by sending 65 the frame to the host forsequential protocol processing. In this case, the host uses this frameto create 51 a CCB, which is then passed to the INIC/CPD to controlsubsequent frames on that connection. The CCB, which is cached 67 in theINIC/CPD, includes control and state information pertinent to allprotocols that would have been processed had conventional software layerprocessing been employed. The CCB also contains storage space forper-transfer information used to facilitate moving application-leveldata contained within subsequent related message packets directly to ahost application in a form available for immediate usage. The INIC/CPDtakes command of connection processing upon receiving a CCB for thatconnection from the host.

As mentioned above, the present invention improves system performance byoffloading TCP/IP data processing from the host protocol stack to theINIC/CPD. Since only the data movement portion of the protocol stack isoffloaded, TCP control processing generally remains on the host protocolstack. In addition, the host protocol stack also handles TCP exceptionprocessing, such as retransmissions. Leaving TCP control and exceptionprocessing on the host protocol stack has the advantage of giving theoperating system complete control over the TCP connection. This isconvenient because the operating system may choose not to hand out aconnection to the network communication device for various reasons. Forexample, if someone wishes to monitor network frames on the host, thehost protocol stack can be programmed to handle all TCP connections, sothat no packets are processed on the INIC/CPD. A second advantage toleaving TCP control and exception processing on the host protocol stackis that this greatly simplifies the complexity of operations required bythe INIC/CPD, which can be made from an inexpensive application specificintegrated circuit (ASIC) as opposed to an expensive CPU.

In order for a connection to be handled by both the host protocol stack44 for control and exception conditions, and by the INIC/CPD 30 for datamovement, the connection context is made to migrate between the host andthe INIC/CPD. A CCB, which contains the set of variables used torepresent the state of a given TCP connection, provides the mechanismfor this migration. Transfer of a CCB from the host to the INIC/CPD istermed a connection handout, and transfer of a CCB from the INIC/CPDback to the host is termed a connection flush. This transfer may occurseveral times during the course of a TCP connection as the result ofdropped packets or other exceptions, which are discussed below. Once aconnection handout occurs, the INIC/CPD handles all TCP processing,according to the fast-path mode. Any message transmissions occurringwhile in the fast-path mode are referred to as fast-path sends.Likewise, any message receptions that occur while in the fast-path modeare referred to as fast-path receives.

A portion of the CCB corresponds to a conventional TCP control block,containing items such as sequence numbers and ports, as well as lowerprotocol values such as IP addresses and the first-hop MAC addresses. Alist of variables for such a conventional TCP control block can be foundin the book by Gary R. Wright and W. Richard Stevens entitled TCP/IPIllustrated, Volume 2 (7^(th) Edition, 1999), which is incorporated byreference herein, on pages 803-805.

In addition to those TCP variables, a number of variables are providedin the CCB for maintaining state information involving the presentinvention. A first of these variables, a character termed conn_nbr,denotes the connection number for this CCB. The INIC/CPD 30 maymaintain, for example, 256 connections, so that the conn_nbr delineateswhich of those connections is defined by this CCB. Another CCB-specificvariable is termed hosttcbaddr, which lists the address in the host forthis particular CCB. This address is used when the CCB is returned fromthe INIC/CPD to the host. For accelerated processing of the most activeconnections, the INIC/CPD 30 stores the connections in a hash table inSRAM. A CCB variable termed Hash Value gives a hash table offset for theCCB, which is a hash of the source and destination IP addresses, andsource and destination TCP ports for the connection.

Another character, termed buff_state, tells whether a CCB that has beencached in SRAM matches the corresponding CCB stored in DRAM. Afterprocessing of a frame or burst of frames against an SRAM cachedconnection, the state of the CCB is changed, which is indicated by thebuff_state character. When the cached connection is flushed back by DMAto DRAM, replacing the CCB held in DRAM with the SRAM CCB having updatedstatus, the character buff_state is set clean.

Additional variables contained in a CCB include a character termedrcv_state, which denotes the status of a receive finite state machinefor the CCB, and a character termed xmt_state, which denotes the statusof a transmit finite state machine for the CCB. Both of these statemachines pertain to fast path processing by the INIC/CPD 30. In otherwords, the state of a fast path receive state machine for a given CCBcan be defined by a number of different values indicated by the settingof the rcv_state character, and the state of a fast path transmit statemachine for that CCB can be likewise be defined by the setting of thexmt_state character. Events processed against the receive and transmitstate machines are denoted in the CCB by characters labeled rcv_evts andxmt_evts, respectively. These event characters offer a history of eventsthat have transpired as well as the current events affecting those statemachines. For example, the rcv_evts character may contain eight bitsdefining previous events and another eight bits defining current events,with the xmt-evts character similarly apportioned.

Also contained in a CCB are variables associated with frames that havebeen received by the INIC/CPD 30 corresponding to the connection. Forexample, fast path received frames may accumulate in the host while theINIC/CPD 30 is waiting for an MDL delineating a host destination for thereceived message. A CCB field termed RcvQ[RCV_MAX] offers a number ofthirty-two-bit words for storing pointers to such frames in DRAM,essentially forming a receive queue. A CCB variable termed OflIO (foroverflow input/output pointers), offers information corresponding to theRcvQ, such as pointers to the last frame in and first frame out, while avariable termed QdCnt indicates the number of frames in the RcvQ.

A number of CCB variables pertain to the MDL that has been provided forstoring a received message. A character termed RHHandle is used toreport to the host a command that has been completed by the INIC/CPD 30regarding that MDL. RNxtDAdd is a CCB field that is used to denote thenext scatter/gather address list to be acquired from DRAM in theINIC/CPD 30 for storage according to the MDL. The variable RCurBuffdescribes the current buffer of the MDL for storing data, and RCurLentells the length of that buffer. Similarly, the variable RNxtBuff tellsthe next receive buffer from the MDL for storing data, and RNxtLen tellsthe length of that buffer. RTotLen is used to designate the total lengthof the MDL, which is reduced as data is stored in the buffers designatedby the MDL.

The CCB similarly keeps track of buffer queues during transmission of amessage. The variable XNxtDAdd pertains to the next address in INIC/CPD30 DRAM from which to acquire a scatter/gather list of data to be sentover a network, while XTotLen provides the total length of the data tobe sent, which is reduced as data is sent. The variable XCurBuffdescribes the current host buffer from which to send data, and XCurLentells the length of that buffer. Similarly, the variable XNxtBuff tellsthe next host buffer from which data is acquired, and XNxtLen tells thelength of that buffer.

Some CCB variables pertain to commands sent from the host stack 44 tothe INIC/CPD 30 during transmission of a message. Several commands sentby the host regarding a particular CCB may be processed at one time bythe INIC/CPD 30, and the CCB maintains variables keeping track of thosecommands. A variable termed XRspSN holds a TCP sequence number for eachmessage that has been sent over a network. This TCP sequence number isused for matching with an acknowledgement (ACK) from the remote host ofreceipt of that transmission. A variable termed XHHandle provides ahandle or DRAM address of the host regarding a particular command, sothat for example upon receiving such an ACK the INIC/CPD can notify thehost. CCB variables that keep track of commands being processed by theINIC/CPD include XCmdIn, which tells the next command storage slot,XCmdOut, which describes the command to be executed, and XCmd2Ack, whichpoints to commands that have been sent but not yet ACKed. XCmdCnts liststhe number of commands currently being processed and commands that havebeen sent but not yet ACKed. XmtQ provides a queued list of all thecommands being processed by the INIC/CPD.

The CCB also contains a couple of fields for IP and TCP checksums,termed ip_ckbase and tcp_ckbase, respectively. Fast-path transmission ofa message occurs with the INIC/CPD prepending protocol headers derivedfrom the CCB to message data provided by the host for the CCB. Theip_ckbase and tcp_ckbase offer the possibility of adjusting the basechecksums provided by the host for prepending to the data along with theheaders.

As mentioned above, fast-path operations can be divided into fourcategories: handout, flush, send and receive. These fast-path operationsmay be implemented in the form of a generic Microsoft Task Offload(TCP_TASK_OFFLOAD), which may be independent from the specific hardwareof the INIC/CPD 30. For the currently preferred implementation,hardware-specific code is placed in the NDIS miniport driver.Implementations for other protocol processing stacks, such as for Unix,Linux, Novel or Macintosh operating systems, may also behardware-independent. The present invention illustrates a Microsoftstack implementation since it involves one of the most popular operatingsystems, and substantial improvements are provided. The descriptionbelow illustrates the modifications required to integrate the four basicfast-path operations into the Microsoft TCP/IP protocol processingstack. Also defined is the format of the TCP_TASK_OFFLOAD as well asmiscellaneous issues associated with these changes.

Support for the fast-path offload mechanisms requires the definition ofa new type of TCP_TASK_OFFLOAD. As with other task offloads, TCP willdetermine the capabilities of the NDIS miniport by submitting anOID_TCP_TASK_OFFLOAD OID to the driver.

Fast-path information is passed between the protocol processing stack 44and the miniport driver 70 as media specific information in anout-of-band data block of a packet descriptor. There are two generalfast-path TCP_TASK_OFFLOAD structures—commands and frames. TheTCP_OFFLOAD_COMMAND structure contains fast-path information that isbeing sent from the TCPIP driver to the miniport. The TCP_OFFLOAD_FRAMEstructure contains fast-path information being sent from the miniport tothe TCPIP driver. The header file that defines the fast-pathTCP_TASK_OFFLOAD mechanism is described on a later page.

Six types of offload commands are defined below:

1] TCP_OFFLOAD_HANDOUT1 (this is the first phase of a two-phasehandshake used in the connection handout);

2] TCP_OFFLOAD_HANDOUT2 (this is the second phase of the two-phasehandshake used in the connection handout);

3] TCP_OFFLOAD_FLUSH (this command is used to flush a connection);

4] TCP_OFFLOAD_SENDMDL (this command is used to send fast-path data);

5] TCP_OFFLOAD_RCVMDL (this is the command used to pass an MDL scattergather list to the INIC/CPD for receive data);

6] TCP_OFFLOAD_WINUPDATE (this command is used to send a TCP windowupdate to the INIC/CPD); and

7] TCP_OFFLOAD_CLOSE (This command is used to close a TCP connectionthat is on the INIC/CPD).

Three types of offload frames are defined below:

1) TCP_OFFLOAD_FRAME_INTERLOCK (this is part of the two-phase handshakeused in the connection handout);

2) TCP_OFFLOAD_FLUSH (this is used by the miniport to flush a connectionto the host);

2) TCP_OFFLOAD_FRAME_DATA (this is used to indicate newly arrivedfast-path data).

FIG. 4 illustrates the migration of a connection context during ahandout from the host protocol processing stack 44 to the INIC/CPD 30via a miniport driver 70 installed in the host 20. Two of the TCPoffload commands and one of the TCP offload frames that were definedabove are illustrated here. The miniport driver 70 converts thesecommands into hardware specific interactions with the INIC/CPD 30.

The connection handout is implemented as a two-phase operation toprevent race conditions. If instead a handout were attempted in asingle-phase operation, there could be a period of time during which theprotocol processing stack 44 had issued the handout but the INIC/CPD 30had not yet received the handout. During this time, slow-path input dataframes could arrive and be processed by the protocol processing stack44. Should this happen, the context information, which the protocolprocessing stack 44 passed to the INIC/CPD 30, would no longer be valid.This potential error is avoided by establishing a provisional context onthe INIC/CPD 30 with the first handout command.

Thus a handout of a CCB from the stack 44 to the INIC/CPD 30 for aconnection to be processed by the fast-path occurs in several steps.First, a TCP_OFFLOAD_HANDOUT1 100 is sent from the stack 44 to theminiport driver 70, which issues a Handout1 command 102 to the INIC/CPD30. The INIC/CPD 30 sends an interlock frame 105 to the miniport driver70 upon receipt of the handout1 command 102, and internally queues anysubsequent frames for the specified connection. Upon receipt of theinterlock frame 105, the miniport driver 70 sends aTCP_OFFLOAD_FRAME_INTERLOCK frame 108 to the stack 44, which interpretsframe 108 as a signal that no further slow-path frames are expected.Stack 44 thereupon completes the handshake by issuing aTCP_OFFLOAD_HANDOUT2 command 110 that includes a CCB, which is forwardedby the miniport driver 70 to the INIC/CPD 30 as a handout2 112. Uponreceipt of the handout2 112, the INIC/CPD 30 reads the contents of theCCB and begins fast-path processing. Note that the CCB address is passedto the miniport in the TCP_OFFLOAD_HANDOUT2 command.

Once a connection has been placed in fast-path mode by the CCB handout,subsequent fast-path commands will require a way to identify theparticular connection. The present invention defines two opaque handlesfor this purpose. A HostContext handle is a value used to uniquelyidentify a connection to the protocol processing stack 44. For TCP/IPmessages the value is the address of the TCP control block. This handleis opaque to the miniport driver 70. A LowerContext handle, on the otherhand, is used to uniquely identify the connection to the miniport driver70 and/or INIC/CPD 30. This handle is opaque to the host stack 44, andimplementation specific to the miniport driver 70. Both the HostContexthandle and LowerContext handle are contained in the TCP_OFFLOAD_COMMANDstructure, while only the HostContext value is contained in theTCP_OFFLOAD_FRAME structure. During a connection handout, the host stack44 passes down the HostContext field to the miniport driver 70. Theminiport driver 70 returns the LowerContext on completing the handoutrequest.

The protocol processing stack 44 on the host has responsibility fordeciding when a connection is to be handed out to the INIC/CPD 30. Aconnection can be handed out to the INIC/CPD 30 as soon as theconnection is fully established and any outstanding exceptions have beenhandled. Nevertheless, the protocol processing stack 44 may choose tonot hand out a connection for a variety of reasons. For example, inorder to preserve resources on the INIC/CPD 30, the host stack 44 maychoose to not handout out slow connections, such as those employingTelnet. The host stack 44 may also use an heuristic method to determinethat a particular connection is too unreliable to warrant putting it infast-path mode.

Either the host protocol processing stack 44 or the INIC/CPD 30 canflush a connection, as shown in FIG. 5. Should the host stack 44 decideto flush a connection, it will issue a TCP_OFFLOAD_FLUSH 120 to theminiport driver 70, which in turn issues a Flush command 122 to theINIC/CPD 30, causing the INIC/CPD 30 to flush the connection. When theINIC/CPD 30 flushes the connection to the stack 44, several operationsare performed that result in sending a Flush frame 125 to the miniportdriver 70, which in turn sends a TCP_OFFLOAD_FRAME_FLUSH 128 to theINIC/CPD 30. For the situation in which the INIC/CPD 30 decides to flushthe connection, the signals 120 and 122 do not exist.

When the INIC/CPD 30 flushes a connection, either by request from thehost stack 44 or by its own decision, it performs several procedures.First, any outstanding fast-path send or receive message transfers arecompleted. When operating in the fast-path mode, a send or receivemessage transfer may involve 64 kilobytes of data, for example. When asend or receive transfer is terminated, information regarding the datasent or received is flushed to the host so that the stack 44 cancontinue processing the send or receive operation. In order to do this,the scatter gather list defining the set of host buffer address andlength pairs for the send or receive message transfer is passed back tothe stack 44, along with information denoting how much data has alreadybeen transferred via the fast-path. Second, the contents of the CCBdefining the fast-path connection are also sent from the INIC/CPD 30back to the host. Note that while a connection is in the fast-path mode,the state of the connection is maintained by the INIC/CPD 30. Thisconnection state is transferred back to the host so that sequencenumbers, etc, are kept in sync. The INIC/CPD 30 does not issue the flushframe to the host stack 44 until both of these steps are complete.

A connection may be flushed for a variety of reasons. For example, thestack 44 will flush if it receives a TDI_DISCONNECT instruction for theconnection, as connection setup and breakdown occurs on the host stack.The INIC/CPD 30 will flush if it encounters a condition that is notallocated to the INIC/CPD for handling, such as expiration of aretransmission timer or receipt of a fragmented TCP segment.

FIG. 6 diagrams a control mechanism for transmitting a message via thefast-path, which may be initiated by the protocol processing stack 44receiving a TDI_SEND request for a connection that is in the fast-pathmode. The steps for controlling this fast-path send of the message to aremote host via the INIC/CPD 30 are simple. The stack 44 creates aTCP_OFFLOAD_COMMAND with the appropriate context handles, the length ofthe message to be sent, and a scatter-gather list or send MDL. A virtualto physical address translation is performed by the host stack 44,although this translation may alternatively be performed by the miniportdriver 70. The fast-path send command will not complete until either allof the data has been sent and acknowledged, or the connection has beenflushed back to the host. If the connection is flushed back to the host,a residual field will indicate how much of the send MDL remains to besent.

A fast-path receive operation begins when a frame arrives on theINIC/CPD 30 for a connection on which no outstanding receive operationis already in progress. As shown in FIG. 7, when such a frame isreceived by the INIC/CPD 30, some or all of the received frame(depending on the frame size) is forwarded 140 to the miniport driver70, which in turn sends 142 a TCP_OFFLOAD_FRAME_DATA frame containingthe forwarded information to the host stack 44. The host stack 44 willin turn communicate with the upper layer interface, which may be a TDIinterface for Microsoft systems, calling a receive handler registered bythe upper layer or application. The amount of data in the receivedmessage frame may be indicated to that host application at this point,which may be termed an indicated length. That frame may also indicatethe size of the data for the entire received message, so that adestination for that data can be earmarked within the host, such as witha scatter-gather list. A total message length that may be specified inan initial frame header is termed an available length.

For example, a NETBIOS message denotes the size of the data in theNETBIOS header, which can optionally be processed by the INIC/CPD 30 andpassed to the upper layer interface for earmarking a final hostdestination in which to place the message data. Alternatively, the hoststack 44 can process an initial NETBIOS header and learn how much moredata is expected for the NETBIOS request. In cases for which a totalmessage is size is unknown, a fictitious indication of large messagelength can be communicated to the upper layer interface, causing theapplication to respond with a large set of destination addresses whichshould have sufficient storage for the message.

Continuing with the example of a Microsoft operating system, if theavailable length is larger than the indicated length, the TDI upperlayer or application will provide an I/O request packet (IRP) with anMDL. This MDL is passed down to the miniport driver 70 in the form of aTCP_OFFLOAD_RCVMDL command, which forwards the command to the INIC/CPD30. Like the fast-path send command, this command contains the contexthandles, the length of the receive MDL, and the scatter-gather listcontained in the MDL. By passing the MDL directly to the INIC/CPD 30,the message data is moved directly to the buffer(s) provided by the TDIupper layer or application, without the data being touched by the CPU.

Subsequent message frames for this connection will be processed solelyby the INIC/CPD 30 and moved into the buffers denoted by the MDL untileither the MDL is filled or the command is flushed back to the host. Ifthe command is flushed back to the host stack 44, then the residualfield will indicate how much unprocessed data remains for the MDL. Ifthe TCP_OFFLOAD_RCVMDL command is completed without error, then theTcpip driver will complete the IRP, at which point the system is readyfor the next TCP_OFFLOAD_FRAME_DATA indication. For messages whose totalsize is not discernable from initial received frames, the connection mayreceive a FIN before the receive MDL is filled. If this occurs a shortcompletion is performed on the receive IRP.

If the INIC/CPD 30 has been given a host destination such as ascatter-gather list or MDL by an upper layer or application, theINIC/CPD will treat data placed in this destination as being accepted bythe upper layer or application. The INIC/CPD 30 may therefore ACKincoming data as it is filling the destination buffer(s) and will keepits advertised receive window fully open.

For small requests, however, there may be no MDL returned by the upperlayer interface such as TDI to the INIC/CPD 30. In this case all of thedata may be absorbed directly in the receive callback function. Toaccount for this, the data which has been accepted by the application isupdated to the INIC/CPD 30 so that the INIC/CPD can update its receivewindow. In order to do this, the host stack 44 can accumulate a count ofdata which has been accepted by the application receive callbackfunction for a connection. From the INIC/CPD's point of view, though,segments sent to the host destination seem to be just “thrown over thewall” unless there is an explicit reply path. To correct thisdeficiency, the update may be piggybacked on requests sent to theINIC/CPD 30, for example via a field in the TCP_OFFLOAD_COMMANDstructure. To deal with a scenario in which the data stream is entirelyone-way, we can also define a TCP_OFFLOAD_WINUPDATE command type toupdate the INIC/CPD.

A converse issue with offloading TCP processing involves keeping hoststack 44 TCP/IP statistics up to date. For example, there is noconventional way for the host stack 44 to know how many TCP segmentswere received by the INIC/CPD 30. We address this issue by introducing aGET_TCP_STATISTICS OID, which is passed to the miniport driver 70 toobtain the TCP statistics. The way that the miniport and INIC/CPD 30maintain these statistics depends upon implementations selected forthose systems.

The host stack 44 creates and maintains a performance monitor (Perfmon)extension dynamic link library (DLL), which can be used to monitorfast-path statistics such as the following: 1) Fast-path/slow-pathsend/receive bytes per second; 2) Fast-path/slow-path send/receivesegments per second; 3) Handouts per second; 4) Flushes per second; and5) Fast-path/slow-path current connections.

Approximately 2500 lines of code are employed to port the fast-pathmodifications to the Microsoft host stack 44, not including comments.The approximate breakdown of this is as follows: 1) Connectionhandout—550 lines of code; 2) Flush—400 lines of code; 3) Send—550 linesof code; 4) Receive—600 lines of code; and 5) Miscellaneous (e.g., statsand perfmon)—250 lines of code.

The fast-path code is implemented in such a way that it requires minimalchanges to the existing TCP/IP host stack 44. Nearly all of theapproximately 2500 lines of code are contained within fast-path specificroutines, which are in turn kept in a single fast-path specific file. Anumber of changes to a Microsoft host stack 44 operation provide theappropriate calls into the fast-path code. These changes are summarizedbelow.

The initialization code queries the adapters for the fast-pathTCP_TASK_OFFLOAD feature and sets the appropriate information in thestructure representing the adapter. Modifications to the TDI datapresentation code are employed to indicate data received. Modificationsare also employed where the host stack 44 receives a TDI Send request.The modified stack 44 then recognizes that a connection is in fast-pathmode and calls the fast-path send routine.

After a TCP connection is set up, the host stack 44 checks thecapabilities of the adapter associated with the connection, and ifappropriate calls the fast-path connection handout routine. Similarly,for a fast-path connection that has been placed into slow-path mode, thehost stack code repeats the handout of the connection once theconnection returns to a standard state.

The ProtocolReceivePacket routine of the host stack 44 is modified toidentify the existence of fast-path TCP_TASK_OFFLOAD information in thepacket. If fast-path information exists, the appropriate fast-pathreceive routine is called.

The ProtocolSendComplete routine of the host stack 44 recognizes thecompletion of a fast-path send, and calls the appropriate fast-path sendcompletion routine.

The TCP input code recognizes when it has received a slow-path frame ona fast-path connection, which indicates a routing loop. If this occursthe host stack 44 implements the flush code.

The TCP connection breakdown code recognizes when a connection is infast path mode and issues a flush before closing the connection.

Paper Appendix A provides source code, written in a C-type language,defining the TCP_TASK_OFFLOAD structures used to implement the fast-pathtask offload.

CD Appendix A contains a hardware description language (verilog code)description of an embodiment of a receive sequencer of a networkinterface device.

CD Appendix B contains microcode executable by a processor on thenetwork interface device. The processor operates in conjunction with thereceive sequencer of CD Appendix A.

CD Appendix C contains a device driver executable on the host as well asan ATCP stack executable on the host. The software of CD Appendix Coperates in conjunction with the network interface device of CDAppendices A and B.

Although we have focused in this document and the accompanying drawingson teaching the preferred embodiment, other embodiments andmodifications will become apparent to persons of ordinary skill in theart in view of this teaching. Therefore, this invention is to be limitedonly by the following claims, which include all such embodiments andmodifications when viewed in conjunction with the specification andaccompanying drawings.

Paper Appendix A

/* ********************************************************  * This filedefines structures and constants used for communication  * between a TCPdriver and a miniport driver for an intelligent  * network card for TCPfastpath offload.********************************************************  */ #if!defined(_(——)TCP_OFFLOAD_(——)H_(——)) #define_(——)TCP_OFFLOAD_(——)H_(——) /*  * Definitions for types ofMEDIA_SPECIFIC_INFO. These are intended  * to not clash with the enumvalues defined in ndis.h  * Eventually these should become publicmembers of that enum.  */ #define TCP_OFFLOAD_CHECKSUM_ID 0x1000 #defineTCP_OFFLOAD_COMMAND_ID 0x1001 #define TCP_OFFLOAD_FRAME_ID 0x1002 /*  *Structure passed as MEDIA_SPECIFIC_INFO carrying info about  * checksumoffload.  * This may be replaced with the official NT5 method when  *this becomes available.  */ typedef struct _TCP_OFFLOAD_CHECKSUM {BOOLEAN DoIpChecksum; BOOLEAN DoTcpChecksum; ULONG HeaderLength; ULONGTcpLength; /* TCP payload size */ USHORT IpCsum; /* Debug verificationonly */ USHORT TcpCsum; /* Debug verification only */ }TCP_OFFLOAD_CHECKSUM, *PTCP_OFFLOAD_CHECKSUM; /*  * In the currentimplementation we are doing physical address  * translation of fastpathMDLs at the TCP driver level.  *  * Note that in other versions, such asthose integrated with NT5,  * we may simply pass the MDL address andhave the  * lower-level driver do the translation  *  * We need to beable to pass a TDI_SEND consisting of a  * NETBIOS header plus 64K ofdata; the latter may not be  * page aligned.  * XXX this definitionshould really depend on PAGE_SIZE,  * but for the moment we are on X86where this is known to be 4K.  */ #define TCP_OFFLOAD_MAXSG   20 /*  *For outgoing data, we don't want individual DMAs for very  * smallbuffer elements (in particular, note that the 4-byte netbios  * headeralways appears in its own separate buffer), so we will  * pass dataelements of 4 bytes or less directly in the command.  * We define acustom scatter/gather element to allow this.  * XXX this could becompressed somewhat as a union, but would  * be less legible...  */typedef struct _TCP_OFFLOAD_SG { ULONG Length; NDIS_PHYSICAL_ADDRESSPhysicalAddress; ULONG InlineLength; UCHAR InlineData[4]; }TCP_OFFLOAD_SG, *PTCP_OFFLOAD_SG; /*  * Structure passed asMEDIA_SPECIFIC_INFO carrying info about  * fastpath commands.  */typedef struct _TCP_OFFLOAD_COMMAND { ULONG CommandCode; /* Handout,Send, etc */ PVOID CommandContext; /* Identifies cmd at TCP   level*/ULONG HostContext; /* Host Context Handle */ ULONG LowerContext; /*Miniport context handle */ ULONG Status; /* On return */ union { struct_TCP_HANDOUTINFO { ULONG SrcIpAddr; /* Initial handout */ ULONGDstIpAddr; /* Initial handout */ USHORT SrcPort; /* Initial handout */USHORT DstPort; /* Initial handout */ UCHAR MacAddr[6]; /* Generalizelater */ } Handout; PVOID TcbAddr; /* 2nd-half handout */ struct_TCP_DATACOMMAND { ULONG WindowUpdate; /* May be 0 */ ULONG TotalLength;/* Send & Rcv */ ULONG Resid; /* flush return */ ULONG Flags; ULONGNumAddrUnits; /* # S/G entries*/ TCP_OFFLOAD_SGAddrList[TCP_OFFLOAD_MAXSG]; } DataCommand; } command_u; }TCP_OFFLOAD_COMMAND, *PTCP_OFFLOAD_COMMAND; /*  * Command codes  */#define TCP_OFFLOAD_HANDOUT1 0 #define TCP_OFFLOAD_HANDOUT2 1 #defineTCP_OFFLOAD_SENDMDL 2 #define TCP_OFFLOAD_RCVMDL 3 #defineTCP_OFFLOAD_WINUPDATE 4 #define TCP_OFFLOAD_FLUSH 5 #defineTCP_OFFLOAD_CLOSE 6 /*  * Status codes.  */ #defineTCP_OFFLOADCMD_SUCCESS 0 #define TCP_OFFLOADCMD_NOCONTEXT 1 #defineTCP_OFFLOADCMD_STALECONTEXT 2 #define TCP_OFFLOADCMD_FLUSH 3 #defineTCP_OFFLOADCMD_FAIL 4 /*  * Data command flags.  */ #defineTCP_OFFLOAD_FORCEACK 1 /* Force ACK on RCV MDL completion */ /*  *Structure passed as MEDIA_SPECIFIC_INFO carrying info about  * fastpathinput frames.  */ typedef struct _TCP_OFFLOAD_FRAME { USHORT FrameType;/* Data, flush, etc */ USHORT Flags; /* PUSH etc */ ULONG HostContext;/* Fastpath connection cookie */ union { struct _FPDATAFRAME { ULONGAvailableLen; /* For indication */ PVOID Payload; /* Actual data */USHORT PayloadLen; /* Length of this */ USHORT IpId; /* debug purposes*/ } DataFrame; USHORT FlushReasonCode; /* For flush frames */ }frame_u; } TCP_OFFLOAD_FRAME, *PTCP_OFFLOAD_FRAME; /*  * Frame types  */#define TCP_OFFLOAD_FRAME_INTERLOCK 0x0000 /* Handout handshake */#define TCP_OFFLOAD_FRAME_DATA 0x0001 /* Data frame */ #defineTCP_OFFLOAD_FRAME_FLUSH 0x0002 /* Flush frame */ /*  * Frame flags; only1 defined at present.  */ #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x0001 /*Rcv'd frame had PSH*/ /*  * Definitions for the size of these varioustypes of tcp offload  * structures contained within aMEDIA_SPECIFIC_INFORMATION  * structure (and therefore including thesize of this up to  * the ClassInformation[ ] field, since theTCP_OFFLOAD  * structures are actually contained within theClassInformation[ ]  * array.)  */ #define TCP_OFFLOAD_CHECKSUM_INFOSIZE\   (sizeof (TCP_OFFLOAD_CHECKSUM) + \   FIELD_OFFSET(MEDIA_SPECIFIC_INFORMATION, ClassInformation)) #defineTCP_OFFLOAD_COMMAND_INFOSIZE \   (sizeof (TCP_OFFLOAD_COMMAND) + \   FIELD_OFFSET(MEDIA_SPECIFIC_INFORMATION, ClassInformation)) #defineTCP_OFFLOAD_FRAME_INFOSIZE \   (sizeof (TCP_OFFLOAD_FRAME) + \   FIELD_OFFSET(MEDIA_SPECIFIC_INFORMATION, ClassInformation)) #endif /*_(——)TCP_OFFLOAD_(——)H_(——) */

1. A method for communication by a host computer that is connectable toa network by a specialized network interface, the method comprising:running a Transmission Control Protocol (TCP) connection on the host,the TCP connection being at least in part identified by a local InternetProtocol (IP) address, a local TCP port, a remote IP address and aremote TCP port, including maintaining TCP state information for theconnection by the host; and offloading the TCP connection from the hostto the network interface, including updating the TCP state informationby the network interface.
 2. The method of claim 1, wherein the networkinterface includes a network interface card (NIC).
 3. The method ofclaim 2, wherein the offloading includes transferring the TCP connectionto the NIC.
 4. The method of claim 2, wherein the network interfaceincludes a device driver for the NIC.
 5. The method of claim 4, whereinthe NIC has a device driver and the offloading is performed bytransferring the TCP connection to the NIC via the device driver.
 6. Themethod of claim 1, wherein the network interface includes acommunication processing device (CPD).
 7. The method of claim 1, whereinthe steps of running and offloading are performed by an operating systemof the host computer.
 8. The method of claim 1, wherein the steps ofrunning and offloading are performed by a protocol processing stack ofthe host computer.
 9. The method of claim 1, further comprising:processing, by the network interface, a packet containing datacorresponding to the TCP connection; and storing, by the networkinterface, the data in a destination in the host that is associated withthe local TCP port.
 10. The method of claim 1, further comprising:transferring control of the TCP connection from the network interface tothe host.
 11. The method of claim 1, further comprising: performing, bythe network interface, TCP processing on a packet corresponding to theTCP connection.
 12. A method for communication by a host computer thatis connectable to a network by an intelligent network interface card(NIC), the method comprising: running a Transmission Control Protocol(TCP) connection on the host, the TCP connection being at least in partidentified by a local Internet Protocol (IP) address, a local TCP port,a remote IP address and a remote TCP port, the TCP connection containinga set of state variables; and transferring the TCP connection from thehost to the NIC.
 13. The method of claim 12, wherein the NIC has adevice driver and the TCP connection is transferred from the host to theNIC via the device driver.
 14. The method of claim 12, wherein the NIChas a device driver and the transferring includes passing stateinformation for the TCP connection to the device driver.
 15. The methodof claim 12, wherein the transferring includes a step for handing outthe TCP connection from the host to the NIC via a device driver.
 16. Themethod of claim 12, wherein the steps of running and transferring areperformed by an operating system of the host computer.
 17. The method ofclaim 12, wherein the steps of running and transferring are performed bya protocol processing stack of the host computer.
 18. The method ofclaim 12, further comprising: processing, by the NIC, a packetcontaining data corresponding to the TCP connection; and storing, by theNIC, the data in a destination corresponding to the local TCP port. 19.The method of claim 12, further comprising: transferring control of theTCP connection from the NIC to the host.
 20. The method of claim 19,wherein the transferring control includes a step for flushing the TCPconnection from the NIC to the host.
 21. The method of claim 12, furthercomprising: performing, by the NIC, TCP processing on a packetcorresponding to the TCP connection.
 22. The method of claim 12, furthercomprising: processing, by the NIC, a packet containing datacorresponding to the TCP connection; and storing, by the NIC, the datain a destination in the host that is associated with the local TCP port.23. A method for communication by a host computer that is connectable toa network by an intelligent network interface card (NIC), the methodcomprising: running a Transmission Control Protocol (TCP) connection bya protocol processing stack of the host computer, the TCP connectionbeing at least in part identified by a local Internet Protocol (IP)address, a local TCP port, a remote IP address and a remote TCP port,including maintaining TCP state information for the connection by theprotocol processing stack; and offloading the TCP connection from theprotocol processing stack to the NIC, including updating the TCP stateinformation by the NIC.
 24. The method of claim 23, wherein the NIC hasa device driver and the offloading includes transferring the TCPconnection to the NIC via the device driver.
 25. The method of claim 23,wherein the NIC has a device driver and the offloading includestransferring the state information for the TCP connection to the devicedriver.
 26. The method of claim 23, wherein the NIC has a device driverand the offloading includes a step for handing out the TCP connectionvia the device driver.
 27. The method of claim 23, further comprisingtransferring control of the TCP connection from the NIC to the protocolstack.
 28. The method of claim 27, wherein the transferring controlincludes a step for flushing the TCP connection from the NIC to theprotocol stack.
 29. The method of claim 23, further comprisingtransferring the state information from the NIC to the protocol stack.30. The method of claim 23, further comprising: processing, by the NIC,a packet containing data corresponding to the TCP connection; andstoring, by the NIC, the data in a destination in the host that isassociated with the local TCP port.